package cn.kgc.controller;

import cn.kgc.pojo.Organization;
import cn.kgc.pojo.employment;
import cn.kgc.service.Service_dyb;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

@Controller
public class Controller_dyb {

    @Resource
    private Service_dyb service_dyb;

    @RequestMapping("/a")
    public String showPosition(Model model){
        return "职位发布管理";
    }

    @ResponseBody
    @RequestMapping("/show")
    public  String showPosition(@RequestParam String positionName,@RequestParam String positionSort,@RequestParam String registranTime,@RequestParam String expirationDate,
                                @RequestParam Integer pageNum,@RequestParam Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<employment> employments = service_dyb.selEmployment(positionName, positionSort,registranTime,expirationDate );
        PageInfo<employment> pageInfo=new PageInfo<employment>(employments);
        return JSON.toJSONStringWithDateFormat(pageInfo,"yyyy-MM-dd");
    }

    @RequestMapping("/getDepartment")
    public String goPosition(Model model){
        List<Organization> organization = service_dyb.getOrganization();
        model.addAttribute("list",organization);
        return "职位发布登记";
    }
}
